#pragma once
#include <QWidget>
#include <QStylePainter>
//#include <vector>
#include <widgets/SCalendar.h>
enum TitleRect
{
	rectRemainName = 0,
	rectRemainValue,
	rectRateName,
	rectRateValue,
	rectRatePatternName,
	rectRatePatternValue,//added by shiy20211108
	rectIssRatingName,
	rectIssRatingValue,
	rectBodyName,
	rectBodyValue,
	rectCdcImpliedName,  //added by shiy20210720
	rectCdcImpliedValue, //added by shiy20210720
	rectCDCName,
	rectCDCValue,
	rectCSName,
	rectCSValue,
	rectRealPrcName,
	rectRealPrc,
	rectRealPrcDirec,
	rectRealBP,
	rectYestodayName,
	rectYestodayPrc,
	rectOpenPrcName,
	rectOpenPrc,
	rectMaxPrcName,
	rectMaxPrc,
	rectMinPrcName,
	rectMinPrc,
	rectPrcNumbName,
	rectPrcNumb,
	rectScoreLevelName,
	rectScoreLevel,
	rectMaxCount
};
class QLabel;
class QPushButton;
class QHBoxLayout;
class BondDetailForm;
class DetailData;
class BondDetailTitleEdit;
class BondDetailTitle : public QWidget
{
public:
    BondDetailTitle(QWidget* p);
    void setDetailData(QSharedPointer<DetailData> d);
private:
	QSharedPointer<DetailData> m_data = nullptr;
	BondDetailTitleEdit* m_edit = nullptr;
    QLabel* m_title = nullptr;
    QPushButton *m_toolBar_calc{nullptr}, *m_toolBar_quote{nullptr}, *m_toolBar_prev{nullptr}, *m_toolBar_next{nullptr};
    QHBoxLayout *m_markers_container{nullptr}; // for optional labels before the title
    BondDetailForm *m_details{nullptr};
protected:
	void paintEvent(QPaintEvent* event) override;
	void mousePressEvent(QMouseEvent* event) override;
	void mouseMoveEvent(QMouseEvent* event) override;
    bool eventFilter(QObject *watched, QEvent *event) override;

private:
    //insert a label into m_markers_container
    void insertMarker(const QString& marker, const QColor& bkColor);
    void fillIssuer();
	void paintLabel(QStylePainter& painter, QRect& issueRect, const QString& label);
	void paintCRM(QStylePainter& painter, QRect& issueRect, const QString& label, QColor bkColor);
    void fillDetails();

	QString GetValue(int nCurrent);
	void computeDrawRect();
	bool DrawShowText(const QRect& rcRect, const QString& stText, QStylePainter* render, QColor pSb, QFont f, QTextOption to, bool bValue);
	enum { emHolidayNull = 0, emHolidayCib, emHolidaySSE};

	void jumpCrmBond();
private:
	QRect				m_rects[rectMaxCount];
	QRect				m_rcHoliday;
	QRect				m_rcIssuer;
	QRect				m_rcCRM;
	int					m_nHolidayType = emHolidayNull;
	QString				m_strHolidayDays;
    QScopedPointer<SCalendar>			m_tipCalendar;
	QDate				m_maturityDay;
};
